
/*
 * Copyright (C) 2011 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *		http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.hisense.settings;


import com.hisense.settings.util.Wrapper;
import com.google.android.tv.settings.TvSettings;

import android.content.Context;
import android.content.BroadcastReceiver;
import android.provider.Settings;
import android.util.Log;
import android.content.Intent;
//import com.marvell.willowtv.framework.features.Picture;
//import com.marvell.willowtv.framework.features.TvFramework;

public class BootWizardStoreModeReceiver extends BroadcastReceiver {

	private static final String TAG = "BootWizardStoreModeReceiver";
	public static final String ACTION_BOOTWIZARD_SETTING = "com.google.tv.tvwelcome.HISENSE_STORE_SETTING";
	private static final String KEY_SOTORE_MODE_ENABLE = "store_mode_enable";
	private String extroName = "STOREMODE";

	private static final int IMAGE_MODE_ENERGYSAVING = 6;
	private static final int IMAGE_MODE_VIVID = 1;

	@Override
	public void onReceive(final Context context, Intent intent) {

		if (ACTION_BOOTWIZARD_SETTING.equals(intent.getAction())) {
			//Picture picture = TvFramework.getInstance().getPictureInstance();
				
			boolean storMode = TvSettings.Secure.getBoolean(context.getContentResolver(),
                						KEY_SOTORE_MODE_ENABLE,false);	
			Log.d(TAG, "ACTION_BOOTWIZARD_SETTING " + ACTION_BOOTWIZARD_SETTING + (storMode?1:0));
			//picture.setRetailMode(storMode);
			if (intent.getBooleanExtra(extroName, false)){
				setRetailMode();
				setEposMode(context);
			}
            else{
            	setHomeMode();
            	resetEposMode(context);
            }
		}
	}
	
	private void setRetailMode() {	
		Wrapper.getWrapperInstance().setPictureMode(IMAGE_MODE_VIVID);
		Log.d(TAG, "setRetailMode " + "setRetailMode ");
	}
	//standard mode
	private void setHomeMode() {	
		Wrapper.getWrapperInstance().setPictureMode(IMAGE_MODE_ENERGYSAVING);
//		Wrapper.getWrapperInstance().setAllSourcePictureMode(IMAGE_MODE_ENERGYSAVING);
		Log.d(TAG, "setHomeMode " + "setHomeMode ");
	}	
	private void setEposMode(Context context) {
		//com.google.android.marvin.talkback/com.google.android.marvin.talkback.TalkBackService
		Settings.Secure.putString(context.getContentResolver(),
		Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES,
		"com.marvell.willowtv.controller/com.hisense.gtv.controller.EPosAccessibilityService");
		Settings.Secure.putInt(context.getContentResolver(),
                Settings.Secure.ACCESSIBILITY_ENABLED, 1);
	}
	private void resetEposMode(Context context) {
		 /*String enabledServicesSetting = Settings.Secure.getString(mContext.getContentResolver(),
	                Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES);
		 if(enabledServicesSetting!=null&&enabledServicesSetting.contains("talkback")){
			 Settings.Secure.putString(getContentResolver(),
	                    Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES,
	                    "");
			 Settings.Secure.putInt(getContentResolver(),Settings.Secure.ACCESSIBILITY_ENABLED, 0);
			 Settings.Secure.putString(getContentResolver(),
	                    Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES,
	                    "com.google.android.marvin.talkback/com.google.android.marvin.talkback.TalkBackService");
			 Settings.Secure.putInt(getContentResolver(),Settings.Secure.ACCESSIBILITY_ENABLED, 1);
		 }else{*/
			 Settings.Secure.putString(context.getContentResolver(),
	                    Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES,
	                    "");
			 Settings.Secure.putInt(context.getContentResolver(),Settings.Secure.ACCESSIBILITY_ENABLED, 0);
		 //}
	
	}
}



